package com.jsnkj.basic.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
import android.text.style.AbsoluteSizeSpan
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.jsnkj.basic.R


/**
 * 打开红包弹窗
 */
class VideoOpenRedDialog(
    var dialogContext: Context,
    var money: Int,
    var click: onItemClickListener
) :
    Dialog(dialogContext),
    View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_video_open_red)
        setCanceledOnTouchOutside(false)
        setCancelable(true)
        window?.setBackgroundDrawableResource(android.R.color.transparent)

        initView()
    }

    fun initView() {
        val imgClose: ImageView = findViewById(R.id.img_close)
        imgClose.setOnClickListener(this)

        val tvOpen: TextView = findViewById(R.id.tv_open)
        tvOpen.setOnClickListener(this)

        val money = "${money} 金币"
        val spannableString = SpannableString(money)

        // 设置“5000”文本的大小
        spannableString.setSpan(
            AbsoluteSizeSpan(35, true), 0, 4, Spanned.SPAN_INCLUSIVE_EXCLUSIVE
        )
        // 设置“金币”文本的大小
        spannableString.setSpan(
            AbsoluteSizeSpan(15, true), 4, money.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE
        )
        findViewById<TextView>(R.id.tv_money).text = spannableString
    }

    override fun onClick(view: View) {
        dismiss()
        when (view.id) {
            R.id.img_close -> {
                click.closeCallBack()
            }

            R.id.tv_open -> {
                click.openItemClickListener()
            }
        }
    }


    interface onItemClickListener {
        fun openItemClickListener()


        fun closeCallBack()
    }

}